package com.x.静态代理.statics;

import com.x.静态代理.Calculator;

import javax.annotation.PostConstruct;

/**
 * ClassName: StaticProxyCalculator
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.03 22:46
 */

/**
 * 不写核心业务 —— 代理类 [中介]
 */
public class StaticProxyCalculator implements Calculator {

    public Calculator calculator;

    public StaticProxyCalculator(Calculator calculator) {
        this.calculator = calculator;
    }


    @Override
    public int add(int i, int j) {
        //非核心代码
        System.out.println("i="+i+", j="+j);
        System.out.println("result=i+j="+calculator.add(i, j));
        return calculator.add(i, j);
    }

    @Override
    public int sub(int i, int j) {
        //非核心代码
        System.out.println("i="+i+", j="+j);
        System.out.println("result=i+j="+calculator.sub(i, j));
        return calculator.sub(i, j);
    }

    @Override
    public int mul(int i, int j) {
        //非核心代码
        System.out.println("i="+i+", j="+j);
        System.out.println("result=i+j="+calculator.mul(i, j));
        return calculator.mul(i, j);
    }

    @Override
    public long div(int i, int j) {
        //非核心代码
        System.out.println("i="+i+", j="+j);
        long result = calculator.div(i, j);
        System.out.println("result=i+j="+result);
        return result;
    }
}
